package com.yxj.tcpDemo1;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        //TCP协议，接收数据

        //1.创建对象ServerSocket
        ServerSocket ss = new ServerSocket(10000);

        //2.监听客户端的链接
        Socket socket = ss.accept();

        //3.从链接通道中获取输入流读取数据
        //InputStream is = socket.getInputStream();
        //以上读取的是字节流，如果输入中文会乱码，此时需要把字节流转换成字符流
        //InputStreamReader isr = new InputStreamReader(is);
        //提搞效率
        //BufferedReader br = new BufferedReader(isr);

        //以上三行代码组合成一行
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        int b;
        while((b = br.read()) != -1) {
            System.out.println((char) b);
        }

        //4.释放资源
        socket.close();
        ss.close();
    }
}
